home *** CD-ROM | disk | FTP | other *** search
/ Basic Instinct 2 Press Kit / Basic Instinct 2 Press Kit.iso / pc / main.dxr / Internal_40_xml.tokenizer.ls < prev    next >
Encoding:
Text File  |  2006-03-15  |  1.3 KB  |  67 lines

  1. property _tokenList, _currPos
  2.  
  3. on new me, str, delims, returnTokens
  4.   case the paramCount of
  5.     2:
  6.       delims = " " & TAB & RETURN
  7.       returnTokens = 0
  8.     3:
  9.       returnTokens = 0
  10.   end case
  11.   me._tokenList = []
  12.   numDelims = delims.length
  13.   delimList = []
  14.   repeat with i = 1 to numDelims
  15.     delimChar = delims.char[i]
  16.     if offset(delimChar, str) then
  17.       delimList.add(delimChar)
  18.     end if
  19.   end repeat
  20.   repeat while str.length
  21.     offsetList = []
  22.     repeat with j in delimList
  23.       charOffset = offset(j, str)
  24.       if charOffset then
  25.         offsetList.add(charOffset)
  26.       end if
  27.     end repeat
  28.     if offsetList.count then
  29.       tokenOffset = min(offsetList)
  30.       if tokenOffset > 1 then
  31.         me._tokenList.add(str.char[1..tokenOffset - 1])
  32.       end if
  33.       if returnTokens then
  34.         me._tokenList.add(str.char[tokenOffset])
  35.       end if
  36.       delete str.char[1..tokenOffset]
  37.       next repeat
  38.     end if
  39.     me._tokenList.add(str)
  40.     str = EMPTY
  41.   end repeat
  42.   me._currPos = 1
  43.   return me
  44. end
  45.  
  46. on countTokens me
  47.   return me._tokenList.count
  48. end
  49.  
  50. on hasMoreTokens me
  51.   if me._currPos <= me._tokenList.count then
  52.     return 1
  53.   else
  54.     return 0
  55.   end if
  56. end
  57.  
  58. on nextToken me
  59.   if me._currPos <= me._tokenList.count then
  60.     token = me._tokenList[me._currPos]
  61.     me._currPos = me._currPos + 1
  62.     return token
  63.   else
  64.     return VOID
  65.   end if
  66. end
  67.